home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / UUCICO / DCPGPKT.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  61KB  |  1,718 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       d c p g p k t . c                                            */
  3. /*                                                                    */
  4. /*       UUCP 'g' protocol module for UUPC/extended.  Supports 7      */
  5. /*       window variable length packets of up yo 512 bytes in         */
  6. /*       length.                                                      */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*--------------------------------------------------------------------*/
  10. /*       Stuart Lynne May/87                                          */
  11. /*                                                                    */
  12. /*       Copyright (c) Richard H. Lamb 1985, 1986, 1987               */
  13. /*       Changes Copyright (c) Stuart Lynne 1987                      */
  14. /*                                                                    */
  15. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  16. /*    Wonderworks.                                                    */
  17. /*                                                                    */
  18. /*    All rights reserved except those explicitly granted by the      */
  19. /*    UUPC/extended license agreement.                                */
  20. /*--------------------------------------------------------------------*/
  21.  
  22. /*--------------------------------------------------------------------*/
  23. /*                          RCS Information                           */
  24. /*--------------------------------------------------------------------*/
  25.  
  26. /*
  27.  *      $Id: dcpgpkt.c 1.18 1993/10/04 03:57:20 ahd Exp $
  28.  *
  29.  *      $Log: dcpgpkt.c $
  30.  * Revision 1.18  1993/10/04  03:57:20  ahd
  31.  * Drop new lines from start up message
  32.  *
  33.  * Revision 1.17  1993/10/02  22:56:59  ahd
  34.  * Suppress compile warning
  35.  *
  36.  * Revision 1.16  1993/10/02  19:07:49  ahd
  37.  * Treat Windows 3.x ala DOS in handling packets in far memory
  38.  *
  39.  * Revision 1.15  1993/09/20  04:41:54  ahd
  40.  * OS/2 2.x support
  41.  *
  42.  * Revision 1.14  1993/07/22  23:22:27  ahd
  43.  * First pass at changes for Robert Denny's Windows 3.1 support
  44.  *
  45.  * Revision 1.13  1993/05/30  00:01:47  ahd
  46.  * Move UUFAR into header file
  47.  *
  48.  * Revision 1.12  1993/04/13  03:19:45  ahd
  49.  * Only perform copy to gspkt if input to gsendpkt is non-null
  50.  *
  51.  * Revision 1.11  1993/04/13  03:00:05  ahd
  52.  * Correct gspkt declare
  53.  *
  54.  * Revision 1.10  1993/04/13  02:26:30  ahd
  55.  * Move buffers to FAR memory
  56.  *
  57.  * Revision 1.9  1993/04/05  04:32:19  ahd
  58.  * Allow unique send and receive packet sizes
  59.  *
  60.  * Revision 1.8  1993/03/06  23:04:54  ahd
  61.  * Make state names more descriptive
  62.  *
  63.  * Revision 1.7  1992/11/21  05:55:11  ahd
  64.  * Use single bit field for gopenpk flag bits, add debugging info
  65.  *
  66.  * Revision 1.6  1992/11/20  12:38:39  ahd
  67.  * Add additional flags to avoid prematurely ending init sequence
  68.  *
  69.  * Revision 1.5  1992/11/19  03:00:29  ahd
  70.  * drop rcsid
  71.  *
  72.  * Revision 1.4  1992/11/17  13:45:37  ahd
  73.  * Add comments from Ian Talyor
  74.  *
  75.  * Revision 1.3  1992/11/16  02:10:27  ahd
  76.  * Rewrite protocol initialize to insure full exchange of packets
  77.  *
  78.  *          25Aug87 - Allow for up to 7 windows - Jal
  79.  *
  80.  *          01Nov87 - those strncpy's should really be memcpy's! -
  81.  *                    Jal
  82.  *
  83.  *          11Sep89 - Raise TimeOut to 15 - ahd
  84.  *
  85.  *          30Apr90 - Add Jordon Brown's fix for short packet
  86.  *                    retries. Reduce retry limit to 20
  87.  *
  88.  *          22Jul90 - Change error retry limit from per host to per
  89.  *                    packet.
  90.  *
  91.  *          22Jul90 - Add error message for number of retries
  92.  *                    exceeded
  93.  *
  94.  *          08Sep90 - Drop memmove to memcpy change supplied by
  95.  *                    Jordan Brown, MS 6.0 and Turbo C++ agree
  96.  *                    memmove insures no overlap
  97.  */
  98.  
  99. /*--------------------------------------------------------------------*/
  100. /*    Thanks goes to John Gilmore for sending me a copy of Greg       */
  101. /*    Chesson's UUCP protocol description -- Obviously invaluable.    */
  102. /*    Thanks also go to Andrew Tannenbaum for the section on          */
  103. /*    Siding window protocols with a program example in his           */
  104. /*    "Computer Networks" book.                                       */
  105. /*--------------------------------------------------------------------*/
  106.  
  107. /*--------------------------------------------------------------------*/
  108. /*                        System include files                        */
  109. /*--------------------------------------------------------------------*/
  110.  
  111. #include <stdio.h>
  112. #include <string.h>
  113. #include <time.h>
  114. #include <stdlib.h>
  115. #include <ctype.h>
  116.  
  117. #ifdef __TURBOC__
  118. #include <mem.h>
  119. #include <alloc.h>
  120. #else
  121. #include <malloc.h>
  122. #endif
  123.  
  124. /*--------------------------------------------------------------------*/
  125. /*                    UUPC/extended include files                     */
  126. /*--------------------------------------------------------------------*/
  127.  
  128. #include "lib.h"
  129. #include "dcp.h"
  130. #include "dcpsys.h"
  131. #include "dcpgpkt.h"
  132. #include "hostable.h"
  133. #include "security.h"
  134. #include "commlib.h"
  135. #include "modem.h"
  136. #include "catcher.h"
  137.  
  138. /*--------------------------------------------------------------------*/
  139. /*                           Local defines                            */
  140. /*--------------------------------------------------------------------*/
  141.  
  142. #define PKTSIZE   MAXPACK
  143. #define MINPKT    32
  144.  
  145. #define HDRSIZE   6
  146. #define MAXTRY 4
  147.  
  148. #ifndef GDEBUG
  149. #define GDEBUG 4
  150. #endif
  151.  
  152. #ifdef __OS2__
  153. #pragma warn -sig
  154. #endif
  155.  
  156. /*--------------------------------------------------------------------*/
  157. /*    Control whether some buffers are placed outside the default     */
  158. /*    data segment                                                    */
  159. /*--------------------------------------------------------------------*/
  160.  
  161. #ifdef __TURBOC__
  162. #define memavail  coreleft
  163. #else
  164. #define memavail  stackavail
  165. #endif
  166.  
  167. /*--------------------------------------------------------------------*/
  168. /*                     g-packet type definitions                      */
  169. /*--------------------------------------------------------------------*/
  170.  
  171. #define DATA   0
  172. #define CLOSE  1
  173. #define NAK    2
  174. #define SRJ    3
  175. #define ACK    4
  176. #define INITC  5
  177. #define INITB  6
  178. #define INITA  7
  179.  
  180. #define POK    -1
  181.  
  182. #define MAXWINDOW 7
  183. #define NBUF   8              /* always SAME as MAXSEQ ? */
  184. #define MAXSEQ 8
  185.  
  186. typedef enum {
  187.       I_EMPTY,
  188.       I_ERROR,
  189.       I_RESTART,
  190.       I_CALLEE,
  191.       I_CALLER,
  192.       I_GRPACK,
  193.       I_INITA_RECV,
  194.       I_INITA_SEND,
  195.       I_INITB_RECV,
  196.       I_INITB_SEND,
  197.       I_INITC_RECV,
  198.       I_INITC_SEND,
  199.       I_COMPLETE
  200.       } I_STATE;
  201.  
  202. #define between(a,b,c) ((a<=b && b<c) || \
  203.                         (c<a && a<=b) || \
  204.                         (b<c && c<a))
  205.  
  206. #define nextpkt(x)    ((x + 1) % MAXSEQ)
  207. #define nextbuf(x)    ((x + 1) % (nwindows+1))
  208.  
  209. /*--------------------------------------------------------------------*/
  210. /*                 Handle 16 bit vs. 32 bit compilers                 */
  211. /*--------------------------------------------------------------------*/
  212.  
  213. #if defined(BIT32ENV)
  214. #define MEMSET(p,c,l)  memset(p,c,l)
  215. #define MEMCPY(t,s,l)  memcpy(t,s,l)
  216. #define MEMMOVE(t,s,l) memmove(t,s,l)
  217. #else
  218. #define MEMSET(p,c,l)  _fmemset(p,c,l)
  219. #define MEMCPY(t,s,l)  _fmemcpy(t,s,l)
  220. #define MEMMOVE(t,s,l) _fmemmove(t,s,l)
  221. #endif
  222.  
  223. /*--------------------------------------------------------------------*/
  224. /*              Global variables for packet definitions               */
  225. /*--------------------------------------------------------------------*/
  226.  
  227. currentfile();
  228.  
  229. static short rwl, swl, swu, rwu, irec, lazynak;
  230. static unsigned short nbuffers;
  231. static short rbl, sbl, sbu;
  232. static KEWSHORT nerr;
  233. static unsigned short outlen[NBUF], inlen[NBUF], xmitlen[NBUF];
  234. static boolean arrived[NBUF];
  235. static size_t nwindows;
  236.  
  237. static char UUFAR outbuf[NBUF][MAXPACK];
  238. static char UUFAR inbuf[NBUF][MAXPACK];
  239. static time_t ftimer[NBUF